/***     
 * 找💣
 */

var _ = require('./../../FrameWork/we_underscore');
var FindSameCardValueTool = require('./FindSameCardValueTool');
var FindFour = module.exports = {};

/**找出炸弹 */
FindFour.getResultBomb = function(_cardInfoList) {
    var tmpCards = FindSameCardValueTool.check(_cardInfoList);
    var findGroup = _.filter(tmpCards, function(_cards) {
        return _.size(_cards) == 4;
    });

    var findGroupMore = [];
    _.each(findGroup, function(_bombCards) {
        findGroupMore.push({
            findGroup: _bombCards,
            otherGroup: _.difference(_cardInfoList, _bombCards)
        })
    });

    return {
        isFind: _.size(findGroupMore) > 0,
        findGroupMore: findGroupMore,
        otherGroup: []
    }
};

FindFour.isSameCard = function(_cardInfoList, _cnt) {
    _cnt = null == _cnt ? 4 : _cnt;
    var tmpCards = FindSameCardValueTool.check(_cardInfoList);
    var findInfo = _.find(tmpCards, function(_cards) {
        return _.size(_cards) == _cnt;
    });
    return !!findInfo;
};

FindFour.isBomb = function(_cardInfoList) {
    var size = _.size(_cardInfoList);
    if (4 != size) {
        return false;
    }
    if (!this.isSameCard(_cardInfoList)) {
        return false;
    }
    var tmpCards = FindSameCardValueTool.check(_cardInfoList);
    if (1 != _.size(tmpCards)) {
        return false;
    }
    return true;
};

/**是否为4带1*/
FindFour.isBeltOne = function(_cardInfoList) {
    var size = _.size(_cardInfoList);
    if (5 != size) {
        return false;
    }
    if (!this.isSameCard(_cardInfoList)) {
        return false;
    }
    var tmpCards = FindSameCardValueTool.check(_cardInfoList);
    if (2 != _.size(tmpCards)) {
        return false;
    }
    return true;
};


/**是否为4带2*/
FindFour.isBeltTwo = function(_cardInfoList) {
    var size = _.size(_cardInfoList);
    if (6 != size) {
        return false;
    }
    if (!this.isSameCard(_cardInfoList)) {
        return false;
    }
    var tmpCards = FindSameCardValueTool.check(_cardInfoList);
    if (3 == _.size(tmpCards)) {
        return true;
    }
    return false;

};

/**是否为4带3*/
FindFour.isBeltThree = function(_cardInfoList) {
    var size = _.size(_cardInfoList);
    if (7 != size) {
        return false;
    }
    if (!this.isSameCard(_cardInfoList)) {
        return false;
    }
    var tmpCards = FindSameCardValueTool.check(_cardInfoList);
    var findGroup = _.map(tmpCards, function(_singleCards) {
        if (4 == _.size(_singleCards)) {
            return _singleCards;
        }
    });

    tmpCards = _.compact(tmpCards);

    if (_.size(findGroup) > 0) {
        return true;
    }
    return false;
};


/**是否为4带2对PAIRS*/
FindFour.isBeltTwoPairs = function(_cardInfoList) {
    var size = _.size(_cardInfoList);
    if (8 != size) {
        return false;
    }
    if (!this.isSameCard(_cardInfoList)) {
        return false;
    }
    var tmpCards = FindSameCardValueTool.check(_cardInfoList);
    var findGroup = _.map(tmpCards, function(_singleCards) {
        if (4 == _.size(_singleCards)) {
            return _singleCards;
        }
    });
    findGroup = _.compact(findGroup);
    if (_.size(findGroup) > 0) {
        var otherGroup = _.map(tmpCards, function(_singleCards) {
            if (2 == _.size(_singleCards)) {
                return _singleCards;
            }
        });
        if (2 == _.size(otherGroup)) {
            return true;
        }
    }
    return false;
};